﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

namespace WpfAdvControls
{
    public class CommonUI
    {
        public static void BindProperty(string propertyName, FrameworkElement element,
            DependencyProperty dependencyProperty, object data)
        {
            var myBinding = new Binding(propertyName);
            myBinding.Source = data;
            element.SetBinding(dependencyProperty, myBinding);
        }

        public static void BindProperty(string propertyName, FrameworkElement element,
            DependencyProperty dependencyProperty, object data, IValueConverter converter)
        {
            var myBinding = new Binding(propertyName);
            myBinding.Source = data;
            myBinding.Converter = converter;
            element.SetBinding(dependencyProperty, myBinding);
        }

        public static void ViewProperties(DockPanel workPanel, Control uiElement)
        {
            if (uiElement != null)
            {
                uiElement.VerticalContentAlignment = VerticalAlignment.Stretch;
                uiElement.HorizontalContentAlignment = HorizontalAlignment.Stretch;
                uiElement.VerticalAlignment = VerticalAlignment.Stretch;
                uiElement.HorizontalAlignment = HorizontalAlignment.Stretch;
                workPanel.Children.Clear();
                workPanel.Children.Add(uiElement);
            }
            else
            {
                workPanel.Children.Clear();
            }
        }
    }
}